﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityLayer;

namespace TestEntity2
{
   public class FirmEntity:IClassEntity
    {
        #region IClassEntity Members
       public const string ObjectXmlFile = "TestEntity2.xml";
       public List<Firm> Firms;
       XmlHelper<Firm> helper;
       public FirmEntity()
       {
           helper = new XmlHelper<Firm>(FirmEntity.ObjectXmlFile);
           Firms = helper.Deserialise();
       }

        public string Name
        {
            get { return "Firm"; }
        }

        public System.Windows.Forms.Form Edit(int ID)
        {
            return new EditFirm(ID, Firms);
        }

        public System.Windows.Forms.Form Add()
        {
            return new EditFirm(null, Firms);
        }

        public List<IObject> Objects
        {
            get {
                List<IObject> res = new List<IObject>();
                foreach (var h in Firms)
                    res.Add(h);
                return res;
            }
        }

        #endregion

        #region IClassEntity Members


        public void Delete(int ID)
        {
            try
            {
                Firms.Remove(Firms.Where(i => i.ID == ID).FirstOrDefault());
                helper.Serialise(Firms);
            }
            catch
            {
            }
        }

        #endregion
       
    }
}
